﻿using BaiTu.CachingServices.CacheEvents;
using BaiTu.CachingServices.Configuration;
using BaiTu.Framework.Core.Interfaces;
using BaiTu.IEventServices;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BaiTu.CachingServices.CacheEventHandlers
{
    public class CachePutEventHandler : IProcessReceivedEventProcessorHandler<CachePutEvent>
    {
        public void Process(CachePutEvent evt)
        {
            CacheCore core = CacheManager.Instance().GetCacheCore(evt.Location);
            if ((CacheConfiguration.Storages[evt.Location].DistributedCacheSetting_PeerCacheServers != null
                && CacheConfiguration.Storages[evt.Location].DistributedCacheSetting_PeerCacheServers.Count > 0)
                ||
                (CacheConfiguration.Storages[evt.Location].DistributedCacheSetting_BackupCacheServer != null))
            {
                object o = core.GetRemote(evt.Key);//get cache item from remote cache server
                core.Set(evt.Key, o);
            }
        }
    }
}
